package com.example.adapter;

import java.util.ArrayList;

import com.example.object.NhanVien;
import com.example.object.PhongBan;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class PhongBanAdapter extends ArrayAdapter<PhongBan> {

	Activity context;
	int layoutId;
	ArrayList<PhongBan> arr;
	public PhongBanAdapter(Activity context,
			int textViewResourceId, ArrayList<PhongBan> objects) {
		super(context, textViewResourceId, objects);
		this.context=context;
		this.layoutId=textViewResourceId;
		this.arr= objects;
		// TODO Auto-generated constructor stub
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		convertView= this.context.getLayoutInflater().inflate(this.layoutId, null);
		TextView txtshortinfo=(TextView) convertView.findViewById(com.example.bai12.R.id.txtshortinfo);
		TextView txtdetailinfo=(TextView) convertView.findViewById(com.example.bai12.R.id.txtdetailinfo);
		PhongBan pb= arr.get(position);
		
		txtshortinfo.setText(pb.toString());
		
		String detail="";
		
		String truongphong="Trưởng Phòng: (CHƯA CÓ)";
		NhanVien nv= pb.getTruongPhong();
		if(nv!=null)
		{
			truongphong="Trưởng Phòng: "+nv.getName();
		}
		
		String phophong="Phó Phòng: (CHƯA CÓ)";
		ArrayList<NhanVien>pplist=pb.getPhoPhong();
		if(pplist.size()>0)
		{	
			phophong="Phó Phòng:\n";
			for(int i=0;i<pplist.size();i++)
			{
				phophong+=(i+1)+" - "+pplist.get(i).getName()+"\n";
			}
		}
		detail=truongphong+"\n"+phophong;
		txtdetailinfo.setText(detail);
		return convertView;
	}

}
